package cn.szzsi._admin;

import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.UserIp;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * Created by admin on 2017/5/31.
 */
public class IpController extends BaseAdminController<UserIp>{
    private String shopId;
    public void list(){
        shopId=getAttr("shopId");
        UserIp ui=UserIp.dao.findFirst("select count(*) pv from mall_user_ip where shopId = ?",shopId);
        List<UserIp>uvs=UserIp.dao.find("select ip from mall_user_ip where shopId = ? group by ip",shopId);
        Long pv=ui.getLong("pv");
        Integer uv=uvs.size();
        setAttr("pv",pv);
        setAttr("uv",uv);
        DecimalFormat df = new DecimalFormat("#.00%");
        String percent="";
        if(new BigDecimal(pv).compareTo(new BigDecimal(0))<=0){
            percent="100%";
        }else {
            percent=df.format((new BigDecimal(uv)).divide(new BigDecimal(pv),4,BigDecimal.ROUND_HALF_DOWN));
        }
        setAttr("percent",percent);
        render(CommonUtil.TEMPLATE_PATH+"/business/userip/user_ip_list.html");
    }
    public void ajaxlist(){
        shopId=getAttr("shopId");
        List<UserIp> lui = UserIp.dao.find("select * from mall_user_ip where shopId = ? order by createDate desc",shopId);
        renderJson(lui);
    }
}
